package cn.calm.xhtml.impl.ui;

import cn.calm.xhtml.annotation.Attribute;
import cn.calm.xhtml.annotation.Tag;
import cn.calm.xhtml.api.exception.XhtmlException;
import cn.calm.xhtml.api.service.ResponseWriter;
import cn.calm.xhtml.api.service.XhtmlContext;
@Tag(namespace = "http://www.calm.cn/xhtml/extras/ui", attributes = {
		@Attribute(name = "value", description = "提交值", template = "<label></label><input name=\"value\"/>"),
		@Attribute(name = "selected", description = "选中表达式", template = "<label></label><input name=\"selected\"/>") })
public class Option extends InputNode {

	public static final String KEYS_SELECTED = "selected";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void processNode(XhtmlContext context) throws XhtmlException {
		createTag(context);
		ResponseWriter writer = context.getResponseWriter();
		writeAttr(context, "value", KEYS_VALUE);

		Object attrValue = getAttrValue(KEYS_SELECTED, context);
		if (attrValue != null) {
			Boolean se=Boolean.valueOf(attrValue.toString());
			if(se){
				writer.writeAttr("selected", "selected");
			}
		}

		writer.write(">");
		processChildren(context);
		writer.endTag(getTag());
	}

	@Override
	public String getTag() {
		return "option";
	}
}
